<template>
    <el-dialog
    title="异常处理"
    :visible="visible"
    width="550px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
    :close-on-click-modal="false"
  >
  <el-form ref="form" :model="form" :rules="rules" label-width="100px">
    <el-form-item label=" 备注:" prop="mark">
        <el-input
          type="textarea"
          :row="5"
          :maxlength="200"
          v-model="form.mark"
          show-word-limit
          placeholder="请输入备注"
          clearable
        />
      </el-form-item>

  </el-form>
  <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" @click="save" :loading="loading"
        >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
    props: {
        // 弹窗是否打开
        visible: Boolean,
        // 修改回显的数据
        data: Object
    },
    data(){
        return{
            // 表单数据
            form: Object.assign({ status: 2 }, this.data),
            // 表单验证规则
            rules:{
                mark: [
                    { required: true, message: '请输入备注', trigger: 'blur' }
                ],
            },
            // 提交状态
            loading: false,
        }
    },
    watch: {
        data() {
            this.form = Object.assign({ status: 2 }, this.data)
        }
    },
    created(){

    },
    mounted(){

    },
    methods:{
        /* 保存编辑 */
        save() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                this.loading = true
                this.$http
                    .post('/orderer/status',{
                        id:this.form.id,
                        status:2,
                        mark:this.form.mark,
                    })
                    .then((res) => {
                    this.loading = false
                    if (res.data.code === 0) {
                        this.$message.success(res.data.msg)
                        this.updateVisible(false)
                        this.$emit('done')
                    } else {
                        this.$message.error(res.data.msg)
                    }
                    })
                    .catch((e) => {
                    this.loading = false
                    this.$message.error(e.message)
                    })
                } else {
                return false
                }
            })
        },
        /* 更新visible */
        updateVisible(value) {
            this.$emit('update:visible', value)
        }
    },
    
}
</script>
<style scoped></style>